// components/dropdownItem/dropdownItem.js
Component({
	options: {
		addGlobalClass: true,
	},
	relations: {
		'../dropdownMenu/dropdownMenu': {
			type: 'parent', // 关联的目标节点应为子节点
			linked: function (target) {
				// 每次有custom-li被插入时执行，target是该节点实例对象，触发在该节点attached生命周期之后
				// console.log(target)
				// console.log(target.data)
			},
			linkChanged: function (target) {
				// 每次有custom-li被移动后执行，target是该节点实例对象，触发在该节点moved生命周期之后
				// console.log(target)
			},
			unlinked: function (target) {
				// 每次有custom-li被移除时执行，target是该节点实例对象，触发在该节点detached生命周期之后
				// console.log(target)
			},
		},
	},
	/**
	 * 组件的属性列表
	 */
	properties: {
		actived: { type: Boolean, value: false },
		value: { type: String, value: '' },
		label: { type: String, value: '' },
	},

	/**
	 * 组件的初始数据
	 */
	data: { parent: null },

	ready() {
		this.getParent()
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		getParent() {
			var nodes = this.getRelationNodes('../dropdownMenu/dropdownMenu')
			let parent = nodes[0]
			// console.log(node)
			this.setData({
				parent,
			})
			this.judgeActived()
		},
		judgeActived() {
			try {
				let parent = this.data.parent
				let value = parent.data.value
				let actived = value === this.data.value
				this.setData({
					actived,
				})
			} catch (error) {}
		},
		clickFn() {
			this.setData({
				actived: true,
			})
			this.data.parent.setValue(this.data.value, this.data.label)
		},
	},
})
